package com.itheima.doudizhu;

import java.util.ArrayList;
import java.util.Collections;

/**
 * @author zhangbaiyan
 * @date 2024-09-13 13:57
 * @description: 扑克牌
 * @version: 1, 0
 */
public class pokerGame {

    //  静态代码块
//  特点:随着类的加载而加载的,而却只只进行一次
    static ArrayList<String> list = new ArrayList<>();

    static {
        //准备牌
        // "♦',"♣","♥","♠"
        // "A","2","3","4","5","6","7","8","9","10","J","Q","K"
        String[] colors = {"♦", "♣", "♥", "♠"};
        String[] numbers = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};

        //牌盒

        for (String color : colors) {
            for (String number : numbers) {
                list.add(color + number);
            }
        }
        list.add("大王");
        list.add("小王");
    }

    public pokerGame() {
        //洗牌
        Collections.shuffle(list);
        //发牌
        ArrayList<String> player1 = new ArrayList<>();
        ArrayList<String> player2 = new ArrayList<>();
        ArrayList<String> player3 = new ArrayList<>();
        ArrayList<String> lord = new ArrayList<>();
        //遍历派和得到每一张牌
        for (int i = 0; i < list.size(); i++) {
            //i:索引
            String poker = list.get(i);
            if(i<=2){
                lord.add(poker);
                continue;
            }
            //给三个玩家轮流发牌
            if(i%3==0){
                player1.add(poker);
            }else if(i%3==1){
                player2.add(poker);
            }else{
                player3.add(poker);
            }
        }
        //看牌
        lookPoker("底牌", lord);
        lookPoker("玩家1", player1);
        lookPoker("玩家2", player2);
        lookPoker("玩家3", player3 );
    }
    public void lookPoker(String name,ArrayList<String> poker) {
        System.out.println(name+"的牌是:");
        for (String s : poker){
            System.out.print(s+" ");
        }
        System.out.println();

    }
}
